package homework;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
/**
 * 手动档动态代理
 * @author Alex
 *
 * @param <E>
 */
public class ProxyList<E> implements List<E> {
    private List<E> target;

    public ProxyList() {
        target = new ArrayList<E>();
    }

    public ProxyList(List<E> list) {
        target = list;
    }

    @Override
    public synchronized int size() {
        return target.size();
    }

    @Override
    public synchronized boolean isEmpty() {
        return target.isEmpty();
    }

    @Override
    public synchronized boolean contains(Object o) {
        return target.contains(o);
    }

    @Override
    public synchronized Iterator<E> iterator() {
        return target.iterator();
    }

    @Override
    public synchronized Object[] toArray() {
        return target.toArray();
    }

    @Override
    public synchronized <T> T[] toArray(T[] a) {
        return target.toArray(a);
    }

    @Override
    public synchronized boolean add(E e) {
        return target.add(e);
    }

    @Override
    public synchronized  boolean remove(Object o) {
        return target.remove(o);
    }

    @Override
    public synchronized  boolean containsAll(Collection<?> c) {
        return target.containsAll(c);
    }

    @Override
    public synchronized  boolean addAll(Collection<? extends E> c) {
        return target.addAll(c);
    }

    @Override
    public  synchronized boolean addAll(int index, Collection<? extends E> c) {
        return target.addAll(index, c);
    }

    @Override
    public synchronized  boolean removeAll(Collection<?> c) {
        return target.removeAll(c);
    }

    @Override
    public synchronized  boolean retainAll(Collection<?> c) {
        return target.retainAll(c);
    }

    @Override
    public  synchronized void clear() {
        target.clear();
    }

    @Override
    public synchronized  E get(int index) {
        return target.get(index);
    }

    @Override
    public  synchronized E set(int index, E element) {
        return target.set(index, element);
    }

    @Override
    public  synchronized void add(int index, E element) {
        target.add(index, element);
    }

    @Override
    public  synchronized E remove(int index) {
        return target.remove(index);
    }

    @Override
    public  synchronized int indexOf(Object o) {
        return target.indexOf(o);
    }

    @Override
    public  synchronized int lastIndexOf(Object o) {
        return target.lastIndexOf(o);
    }

    @Override
    public synchronized  ListIterator<E> listIterator() {
        return target.listIterator();
    }

    @Override
    public synchronized  ListIterator<E> listIterator(int index) {
        return target.listIterator(index);
    }

    @Override
    public synchronized  List<E> subList(int fromIndex, int toIndex) {
        return target.subList(fromIndex, toIndex);
    }

}
